﻿using BonjourQuotation.DataAccess.Repositories;
using BonjourQuotation.ObjectModel.AccountData;
using BonjourQuotation.ObjectModel.ErrorData;
using BonjourQuotation.ObjectModel.PreferredVendorData;
using BonjourQuotation.ObjectModel.LoggerData;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace BonjourQuotation.UI.ServiceManagers
{
    public class PreferredVendorManager
    {
        private readonly log4net.ILog logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        public ErrorBInfo CreateVendorContract(PreferredVendorContractsBData VendorContractData)
        {
            try
            {
                var proxy = new PreferredVendorRepository();
                return proxy.CreateVendorContract(VendorContractData);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public ErrorBInfo CreateVendorContractDetail(PreferredVendorContractsFromDetailsBData VendorContractDetailData)
        {
            try
            {
                var proxy = new PreferredVendorRepository();
                return proxy.CreateVendorContractDetail(VendorContractDetailData);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public ManagePreferredVendorsGridBData GetAllVendors(int PageNumber)
        {
            try
            {
                var proxy = new PreferredVendorRepository();
                return proxy.LoadAllVendors(PageNumber);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public ManagePreferredVendorsGridBData GetSearchedVendors(ManagePreferredVendorsGridBData model)
        {
            try
            {
                var proxy = new PreferredVendorRepository();
                return proxy.LoadSearchedVendors(model);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public PreferredVendorDetailsBData GetVendorDetailsByID(int VendorID)
        {
            try
            {
                var proxy = new PreferredVendorRepository();
                return proxy.LoadVendorDetailsByID(VendorID);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  

        }
        public PreferredVendorContractsBData GetVendorContractsByID(int VendorID)
        {
            try
            {
                var proxy = new PreferredVendorRepository();
                return proxy.LoadVendorContractsByID(VendorID);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public PreferredVendorContractsFromDetailsBData GetVendorContractDetailsByID(int VendorID, int SeasonID)
        {
            try
            {
                var proxy = new PreferredVendorRepository();
                return proxy.LoadVendorContractDetailsByID(VendorID, SeasonID);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public PreferredVendorGroupsBData GetVendorGroupsByID(int VendorID)
        {
            try
            {
                var proxy = new PreferredVendorRepository();
                return proxy.LoadVendorGroupsByID(VendorID);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public ErrorBInfo PostVendorDetailsData(PreferredVendorDetailsBData VendorData)
        {
            try
            {
                var proxy = new PreferredVendorRepository();
                return proxy.SaveVendorDetailsData(VendorData);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public ErrorBInfo PostVendorContractsData(List<PreferredVendorContractsRowBData> VendorContractData, int VendorID)
        {
            try
            {
                var proxy = new PreferredVendorRepository();
                return proxy.SaveVendorContractsData(VendorContractData, VendorID);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public ErrorBInfo PostVendorContractDetailsData(PreferredVendorContractsFromDetailsBData VendorContractDetailsData)
        {
            try
            {
                var proxy = new PreferredVendorRepository();
                return proxy.SaveVendorContractDetailsData(VendorContractDetailsData);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public ErrorBInfo UpdateVendorContractPath(int VendorID, int SeasonID, string VendorContractPath)
        {
            try
            {
                var proxy = new PreferredVendorRepository();
                return proxy.UpdateVendorContractPath(VendorID, SeasonID, VendorContractPath);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public Dictionary<int, string> LoadArea(int RegionID)
        {
            try
            {
                var proxy = new PreferredVendorRepository();
                return proxy.LoadArea(RegionID);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public Dictionary<int, string> LoadRegion(int CountryID)
        {
            try
            {
                var proxy = new PreferredVendorRepository();
                return proxy.LoadRegion(CountryID);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public Dictionary<string, string> LoadState()
        {
            try
            {
                var proxy = new PreferredVendorRepository();
                return proxy.LoadState();
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public Dictionary<int, string> LoadCity(int CountryID, string StateID)
        {
            try
            {
                var proxy = new PreferredVendorRepository();
                return proxy.LoadCity(CountryID, StateID);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
    }
}